<?php if (!defined('THINK_PATH')) exit();?><section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body">
                    <form id="category_category_add_dialog_form">
                        <input type="hidden" name="id" value="<?php echo ($info["catid"]); ?>"/>
                        <table width="100%" class="table ">
                            <tr>
                                <td width="100">上级栏目：</td>
                                <td><input id="category_category_add_dialog_form_parentid"
                                           name="info[parentid]"
                                           class="easyui-combotree" value="<?php echo ((isset($parentid) && ($parentid !== ""))?($parentid):0); ?>"
                                           style="width:180px;height:26px"/></td>
                                <td>
                                    <div id="category_category_add_dialog_form_parentidTip"></div>
                                </td>
                            </tr>
                            <tr>
                                <td>栏目名称：</td>
                                <td><input id="category_category_add_dialog_form_catname" name="info[catname]"
                                           value="<?php echo ($info["catname"]); ?>" type="text" style="width:178px;height:22px"/></td>
                                <td>
                                    <div id="category_category_add_dialog_form_catnameTip"></div>
                                </td>
                            </tr>
                            <tr>
                                <td>栏目类型：</td>
                                <td>
                                    <select id="category_category_add_dialog_form_type" name="info[type]"
                                            class="easyui-combobox"
                                            data-options="editable:false,panelHeight:'auto',onChange:categoryCategoryAddDialogFormTypeChange"
                                            style="width:80px"
                                    <?php if(!empty($info)): ?>disabled<?php endif; ?>
                                    >
                                    <?php if(is_array($typelist)): foreach($typelist as $key=>$type): ?><option value="<?php echo ($key); ?>"
                                        <?php if(($info["type"]) == $key): ?>selected<?php endif; ?>
                                        ><?php echo ($type); ?></option><?php endforeach; endif; ?>
                                    </select>
                                    <span style="color:gray;padding-left:15px">提示：设置后将不可修改</span>
                                </td>
                                <td>
                                    <div id="category_category_add_dialog_form_typeTip"></div>
                                </td>
                            </tr>
                            <tr id="category_category_add_dialog_form_url"
                            <?php if(($info["type"]) != "2"): ?>style="display:none"<?php endif; ?>
                            >
                            <td>链接：</td>
                            <td colspan="2"><input name="info[url]" value="<?php echo ($info["url"]); ?>" type="text"
                                                   style="width:80%;height:22px"/></td>
                            </tr>
                            <tr>
                                <td>描述：</td>
                                <td colspan="2"><textarea name="info[description]" style="width:80%;height:60px"><?php echo ($info["description"]); ?></textarea>
                                </td>
                            </tr>
                            <tr>
                                <td>是否启用：</td>
                                <td colspan="2">
                                        <label><input name="info[ismenu]" value="1" type="radio"
                                            <?php if(!isset($info) or $info["ismenu"] == '1'): ?>checked<?php endif; ?>
                                            />是</label>
                                        <label><input name="info[ismenu]" value="0" type="radio"
                                            <?php if(($info["ismenu"]) == "0"): ?>checked<?php endif; ?>
                                            />否</label>
                                </td>
                            </tr>
                        </table>
                        <div class="box-footer">
                            <span class="input-group-btn">
                                <button class="btn btn-danger pull-left" type="button" id="close-dialog">取消</button>

                                <button class="btn btn-primary pull-right" type="button" id='form_submit'>提交</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    $(function () {
        $('#form_submit').click(function () {
            $('#category_category_add_dialog_form').submit();
        });
        $('#category_category_add_dialog_form_parentid').combotree({url: "<?php echo U('Category/public_categorySelect');?>"});
        $('#category_category_add_dialog_form_type').combobox();
        $.formValidator.initConfig({
            formID: "category_category_add_dialog_form",
            onError: function (msg) {
            },
            onSuccess: categoryCategoryAddDialogFormSubmit,
            submitAfterAjaxPrompt: '有数据正在异步验证，请稍等...',
            inIframe: true
        });
        $("#category_category_add_dialog_form_parentid").formValidator({
            onShow: "请选择上级栏目",
            onFocus: "上级栏目不能为空"
        }).inputValidator({min: 0, type: 'value', onError: "上级栏目不能为空"}).defaultPassed();
        $("#category_category_add_dialog_form_catname").formValidator({
            onShow: "请输入栏目名称",
            onFocus: "栏目名称不能为空",
            onCorrect: "输入正确"
        }).inputValidator({
            min: 1,
            empty: {leftEmpty: false, rightEmpty: false, emptyError: '栏目名称不能有空格'},
            onError: "栏目名称不能为空"
        });
    })

    function categoryCategoryAddDialogFormSubmit() {
        $.post("<?php echo U('Category/categoryAdd');?>", $("#category_category_add_dialog_form").serialize(), function (res) {
            if (!res.status) {
                $.messager.alert('提示信息', res.info, 'error');
            } else {
                $.messager.alert('提示信息', res.info, 'info');
                dialog.get('dialogPage').close().remove();
                reloadContent();
            }
        })
    }
    function categoryCategoryAddDialogFormTypeChange(val) {
        if (val == '2') {
            $('#category_category_add_dialog_form_url').show();
        } else {
            $('#category_category_add_dialog_form_url').val('');
            $('#category_category_add_dialog_form_url').hide();
        }
    }
</script>